package com.feiyuan.modules.sys.service.impl;

import com.feiyuan.common.exception.FeiyuanException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feiyuan.common.utils.PageUtils;
import com.feiyuan.common.utils.Query;

import com.feiyuan.modules.sys.mapper.DictTabulateDao;
import com.feiyuan.modules.sys.entity.DictTabulateEntity;
import com.feiyuan.modules.sys.service.DictTabulateService;


@Service("dictTabulateService")
public class DictTabulateServiceImpl extends ServiceImpl<DictTabulateDao, DictTabulateEntity> implements DictTabulateService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String keyword = (String) params.get("keyword");
        String dictId = (String) params.get("dictId");
        if (StringUtils.isEmpty(dictId)) {
            throw new FeiyuanException("字典父级ID不能为空!", 500);
        }
        IPage<DictTabulateEntity> page = this.page(
                new Query<DictTabulateEntity>().getPage(params),
                new QueryWrapper<DictTabulateEntity>().eq("dict_id", dictId).like(StringUtils.isNotEmpty(keyword), "tag_name", keyword)
                        .or().like(StringUtils.isNotEmpty(keyword), "tag_desc", keyword).orderByAsc("tag_sort")
        );

        return new PageUtils(page);
    }

}